const HtmlWebpackPlugin = require('html-webpack-plugin')
const URL = require('urijs')
const _ = require('lodash')

class MyPlugin {
	constructor(options) {
		this.options = options
	}

	apply(compiler) {
		let self = this;
		
		compiler.plugin('compilation', function (compilation) {
			compilation.plugin('html-webpack-plugin-before-html-processing', function (data, callback) {
				//console.log(data)
				const cssList = _.get(data, 'assets.css');
				if (_.isArray(cssList)) {
					data.assets.css = data.assets.css.map(css => {
						return new URL(css).origin(self.options.options.css).toString()
					})
				}

				data.assets.css = data.assets.css
				callback(null, data);
			});
		});
	}
}

module.exports = MyPlugin
